/*
============================================================================
 Name        : XmlEngine.h
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : CXmlEngine declaration
============================================================================
*/

#ifndef __XMLENGINE_H__
#define __XMLENGINE_H__

// INCLUDES
#include <e32std.h>
#include <e32base.h>

#include <SyExpat.h>
#include "MXmlObserver.h"

#ifdef _DEBUG
#include <flogger.h>
#endif


// CLASS DECLARATION
class CXmlEngine : public CBase, public MSyDocHandler
{
public: // Constructors and destructor
	IMPORT_C ~CXmlEngine();
	IMPORT_C static CXmlEngine* NewL(MXmlObserver& aObserver);
	IMPORT_C static CXmlEngine* NewLC(MXmlObserver& aObserver);

private:
	CXmlEngine(MXmlObserver& aObserver);
	void ConstructL();

private: //from MSyDocHandler
	void StartElement(const TQualified& aName, const RArray<TAttribute>& attributes);
	void EndElement(const TQualified& aName);
	void CharacterData(const TDesC& aData);
	
	void ProcessingInstruction(const TDesC&, const TDesC&) {}
	void Comment(const TDesC&) {}
	void StartCDataSection() {}
	void EndCDataSection() {}
	void Default(const TDesC&) {}
	
	virtual void SetParser(CExpatParserBase* ) {}

public: //new functions
	IMPORT_C void ParseL(const TPtrC8 aBuffer, const TBool aIsFinal);
	IMPORT_C void Cancel();

private:
	CSyParser* iReader;
	MXmlObserver& iObserver;
	TInt iDepth;
	TBool iElementStarted;

	HBufC* iCurrentName;
	HBufC* iCurrentData;
	RArray<TXmlAttribute> iCurrentAttributes;
	
	TBool iIsCancelled;

#ifdef _DEBUG
	RFileLogger iLog;
#endif
};

#endif // __XMLENGINE_H__
